import java.sql.*;

public class JDBCFirst {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=utf8&useSSL=true";
        String username = "root";
        String passwd = "0028";
        Connection connection = DriverManager.getConnection(url, username, passwd);
        Statement statement = connection.createStatement();
        String sql = "SELECT * FROM cats";
        ResultSet resultSet = statement.executeQuery(sql);
        while(resultSet.next()) {
            System.out.println("id:" + resultSet.getObject("id"));
            System.out.println("name:" + resultSet.getObject("name"));
            System.out.println("age:" + resultSet.getObject("age"));
        }
        resultSet.close();
        statement.close();
        connection.close();

        System.out.println("鸣谢：@猫在山大公众号及山东大学动物保护协会提供的数据！");
    }
}
